package com.piggy.logi.sys.service.impl;

import java.util.HashSet;
import java.util.Set;

import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.service.ILogiSysPermissionService;
import com.piggy.logi.sys.service.ILogiSysUserService;
import org.springframework.stereotype.Service;

import com.piggy.logi.sys.api.domain.LogiSysUser;
import com.piggy.logi.sys.service.ILogiSysMenuService;
import com.piggy.logi.sys.service.ILogiSysRoleService;

import javax.annotation.Resource;

@Service
public class LogiSysPermissionServiceImpl implements ILogiSysPermissionService {
    @Resource
    private ILogiSysRoleService roleService;

    @Resource
    private ILogiSysMenuService menuService;

    @Resource
    private ILogiSysUserService userService;

    /**
     * 获取角色数据权限
     *
     * @param userId 用户Id
     * @return 角色权限信息
     */
    @Override
    public Set<String> getRolePermission(Long userId) {
        Set<String> roles = new HashSet<>();
        // 管理员拥有所有权限
        if (SecurityUtils.isAdmin(userId)) {
            roles.add("admin");
        } else {
            roles.addAll(roleService.selectRolePermissionByUserId(userId));
        }
        return roles;
    }

    /**
     * 获取菜单数据权限
     *
     * @param userId 用户Id
     * @return 菜单权限信息
     */
    @Override
    public Set<String> getMenuPermission(Long userId) {
        Set<String> perms = new HashSet<>();
        // 管理员拥有所有权限
        LogiSysUser user = userService.selectUserById(userId);
        /*if (SecurityUtils.isSysAdmin(user.getRoleKeys())||SecurityUtils.isLogiDriver(user.getRoleKeys())) {
            perms.add("*:*:*");
        } else {
            perms.addAll(menuService.selectMenuPermsByUserId(userId));
        }*/
        perms.add("*:*:*");
        return perms;
    }
}
